<template>
  <view class="paper">
    <view class="card">
      <view class="title" v-if="info.score >= 40">考试合格</view>
      <view class="title" v-else>考试不合格</view>
      <view class="status">
        <image v-if="info.score >= 40" src="/static/icon/success.png" mode=""></image>
        <image v-else src="/static/icon/error.png" mode=""></image>
      </view>
      <view class="form">
        <view class="form-item">
          <view class="label">考试名称</view>
          <view class="value">{{ info.name }}</view>
        </view>
        <view class="form-item">
          <view class="label">考试用时</view>
          <view class="value">{{ timeText }}</view>
        </view>
        <view class="form-item">
          <view class="label">考试成绩</view>
          <view class="value">
            <text class="instore">{{ info.score }}</text>
            <text>分</text>
          </view>
        </view>
      </view>
    </view>
    <view class="action-bottom">
      <text class="check-txt" @click="handleJx">查看解析</text>
      <button class="cu-btn nxt-btn down-btn" @click="handStar">
        <text>重新考试</text>
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      info: {},
      timeText: '',
      city: '',
      mock_exam_id: ''
    }
  },
  onLoad (e) {
    console.log(e)
    this.city = e.city
    this.mock_exam_id = e.mock_exam_id
    this.info = getApp().globalData.examinationSuccess
    const time = this.getTime(this.info.exam_time)
    this.timeText = time
  },
  methods: {
    handleJx () {
      console.log('解析');
      console.log(this.info, 'info');

      uni.redirectTo({
        url: `/pages/paper/answer?type=4&id=${this.mock_exam_id}&name=${this.city}&isJx=true`
      })
    },
    handStar () {
      uni.redirectTo({
        url: `/pages/examination/examination?name=${this.info.name}&type='back'&name=${this.city}`
      })
    },
    getTime (time) {
      // 转换为式分秒
      let h = parseInt(time / 60 / 60 % 24)
      h = h < 10 ? '0' + h : h
      let m = parseInt(time / 60 % 60)
      m = m < 10 ? '0' + m : m
      let s = parseInt(time % 60)
      s = s < 10 ? '0' + s : s
      // 作为返回值返回
      return m + '分' + s + '秒'
    }
  }
}
</script>

<style lang="scss" scoped>
.paper {
  min-height: 100vh;
  background-color: #F5F6F9;
  padding-top: 48rpx;

  .card {
    width: 702rpx;
    background: #FFFFFF;
    border-radius: 20rpx;
    margin: 0 auto;
    padding: 60rpx 39rpx;
    position: relative;

    .status {
      position: absolute;
      right: 31rpx;
      top: 71rpx;

      image {
        width: 134rpx;
        height: 118rpx;
      }
    }

    .title {
      text-align: center;
      font-size: 52rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #2D3341;
    }

    .form {
      padding: 60rpx 0rpx 0 0rpx;

      &-item {
        display: flex;
        align-items: center;
        border-bottom: 1px solid #EBECF0;
        padding: 40rpx 0 20rpx 0;

        .label {
          color: #222;
          font-size: 30rpx;
        }

        .value {
          margin-left: 20rpx;
          font-size: 30rpx;
          color: #444;

          .instore {
            color: #FF6F36;
            font-size: 33rpx;
          }
        }
      }
    }
  }
}

.action-bottom {
  width: 702rpx;
  position: fixed;
  bottom: 120rpx;
  left: 24rpx;

  .nxt-btn {
    width: 100%;
    height: 92rpx;
    background: #E3E3E3;
    border-radius: 20rpx;
    overflow: hidden;
    transition: height 0.25s;
  }

  .check-txt {
    display: flex;
    justify-content: center;
    margin-bottom: 20rpx;
    color: #2979ff;
  }

  .down-btn {
    background-color: #36c269;
    color: #FFFFFF;
  }
}
</style>